class Student(object):
    def __init__(self, name, score):
        self.name = name
        self.score = score

    def print_score(self):
        print("%s:%s" % (self.name, self.score))

    def get_grade(self):
        if self.score >= 90:
            return 'A'
        elif self.score > 60:
            return 'B'
        else:
            return 'C'


# bart = Student("张三", 99)
# bart.print_score()
# grade = bart.get_grade()
# print(grade)


class Student_one(object):
    def __init__(self, name, score):
        self._name = name
        self._score = score

    def get_name(self):
        return self._name

    def get_score(self):
        return self._score

    def set_score(self, score):
        if 0 <= score <= 100:
            self._score = score
        else:
            raise ValueError("bad score")

    def print_score(self):
        print("%s:%s" % (self._name, self._score))

    def get_grade(self):
        if self._score >= 90:
            return 'A'
        elif self._score >= 60:
            return 'B'
        else:
            return 'C'


bart = Student("张三", 99)


# print(bart.name)
# new_score=bart.score=34
# bart.core=900
# print(bart.get_grade())


def abss(x):
    if not isinstance(x, (int, float)):
        raise ValueError("bad operand type")
    if x > 0:
        return x
    else:
        return -x


# print(abss('99'))

import math


def move(x, y, step, angle=0):
    nx = x + step * math.cos(angle)
    ny = y + step * math.sin(angle)
    return nx, ny


# x, y = move(100, 100, 60, math.pi / 6)
# print(x,y)
# r=move(1000,00,80,math.pi/7)
# print(r)


def power(x):
    return x * x


w = power(45)


# print(w)


def po(x, n):
    s = 1
    while n > 0:
        n = n - 1
        s = s * x
    return s


# print(po(5, 4))


def pow(x, n=2):
    s = 1
    while n > 0:
        n = n - 1
        s = s * x
    return s


# print(pow(5,3))


def enroll(name, gender, age=6, city='shanghai'):
    # print('name', name)
    # print('gender', gender)
    # print('age', age)
    # print('city', city)
    return name, gender, age, city


# zansan=enroll('zs','F')
zansan = enroll('zs', 'F', 8)


# print(zansan)


def add_end(L=[]):
    L.append('END')
    return L


# print(add_end([1,2,3]))
# print(add_end(['x','y','z']))

a = add_end()
# print(a)

b = add_end()
# print(b)

c = add_end()


# print(c)

# 函数似乎每次都“记住了”上次添加了'END'后的list


def addd_end(L=None):
    if L is None:
        L = []
    L.append('END')
    return L


aa = addd_end()
# print(aa)

bb = addd_end()


# print(bb)
# s = 0
# for i in range(5):
#     s = i + s
# if i==100:
#     break

# print(list(range(5)))


def calc(number):
    sum = 0
    for n in number:
        sum = sum + n * n
    return sum


# print(calc([1, 2, 3]))
# print(calc((1,2,3)))
# 可变参数
def calcc(*number):
    sum = 0
    for n in number:
        sum = sum + n * n
    return sum


calcc(1, 2)
# print(calcc(1, 2, 3, 4))
nums = [1, 2, 3]


# print(calcc(*nums))


# 关键字参数
def person(name, age, **kw):
    print('name:', name, 'age:', age, 'other:', kw)


# print(person('zs',23))
# print(person('zs',23,city='shanghai'))
# print(person('zs',23,gender='M',job='cs'))
# person('zs', 23, gender='M', job='cs')

extra = {'city': "shanghai", 'job': 'cs', }


# person('jack', 23, **extra)
# 命名关键字参数
def persionn(name, age, *, city, job):
    print(name, age, city, job)


# 命名关键字参数必须传入参数名，这和位置参数不同。如果没有传入参数名，调用将报错
# 使用命名关键字参数时，要特别注意，*不是参数，而是特殊分隔符。如果缺少*，Python解释器将无法识别位置参数和命名关键字参数
persionn('ls', 33, city='xi`an', job='engineer')


# 参数组合
# 参数定义的顺序必须是：必选参数、默认参数、可变参数/命名关键字参数和关键字参数。
def new_woker(name, age, gender, *hobby, **address):
    print("name:", name, "age:", age, 'gender:', gender, 'department=', 'test', hobby, address)


new_woker('zhangsan', 74, 'W')
new_woker('wangwu', 44, 'M', 'basketball', 'football')
new_woker('lisi', 19, 'M', address1='宝安区沙井', address2='龙华区民治')
